<?php

define('ACC', true);
require ('../includes/init.php');
$attr = new AttrModel();

if($_GET['act'] == 'list'){
	
	if(isset($_GET['cat_id'])){
		$cat_id = $_GET['cat_id']+0;
	}
	
	$cat_name = $attr->get_cat_name($cat_id);
	$attr_list = $attr->get_attr_list($cat_id);
	$cat_list = $attr->get_cat_list();

	$smarty->assign('cat_id', $cat_id);
	$smarty->assign('cat_list', $cat_list);
	$smarty->assign('cat_name', $cat_name);
	$smarty->assign('attr_list', $attr_list);
	$smarty->assign('title', '商品属性');
	$smarty->assign('url', 'attribute.php?act=add&cat_id='.$cat_id);
	$smarty->assign('link', '添加属性');
	
	$smarty->display('./admin/attribute_list.html');
	
}else if($_GET['act'] == 'add'){
	
	$cat_id = $_GET['cat_id'];

	$cat = $attr->get_cat_row($cat_id);
	$cat_list = $attr->get_cat_list($cat_id);

	$smarty->assign('judge', 'add');
	$smarty->assign('cat', $cat);
	$smarty->assign('cat_list', $cat_list);
	$smarty->assign('title', '添加属性');
	$smarty->assign('url', 'attribute.php?act=list');
	$smarty->assign('link', '商品属性');
	
	$smarty->display('./admin/attribute_info.html');
	
}else if($_GET['act'] == 'search'){
	
	$cat_id = $_GET['cat_id'] + 0;
	if($cat_id != 0){
		$attr_list = $attr->get_attr_list($cat_id);
	}else{
		$attr_list = $attr->get_attr_all();
	}
	
	$cat_name = $attr->get_cat_name($cat_id);
	$str = '';
	$str .= '<tr><th>编号</th><th>属性名称</th><th>商品类型</th><th>属性值的录入方式</th><th>属性可选值</th><th>操作</th></tr>';
	foreach($attr_list as $val){
		$str .= '<tr>';
		$str .= '<td nowrap="true" valign="top"><span>' . $val['attr_id'] . '</span></td>';
		$str .= '<td class="first-cell" nowrap="true" valign="top"><span>' . $val['attr_name'] . '</span></td>';
		$str .= '<td nowrap="true" valign="top"><span>' . $cat_name . '</span></td>';
		$str .= '<td nowrap="true" valign="top"><span>' . $val['attr_input_type'] . '</span></td>';
		$str .= '<td valign="top"><span>' . $val['attr_values'] . '</span></td>';
		$str .= '<td align="center" nowrap="true" valign="top">';
		$str .= '<a href="attribute.php?act=edit&attr_id=';
		$str .= "$val[attr_id]" . ' title="编辑"><img src="images/icon_edit.gif" border="0" height="16" width="16"></a>';

		$str .= '<a href="javascript:;" onclick="remove(this,' . "'attribute.php?act=delete&attr_id=<{" . '$attr.attr_id' . "}>)'" . ' title="删除">' . '<img src="images/icon_drop.gif" border="0" height="16" width="16"></a>';

		
		$str .= '</td>';
		$str .= '</tr>';
	}
	echo $str;
	return;
	
}else if($_GET['act'] == 'delete'){

	if($attr->delete_attr($_GET['attr_id'])){
		echo 1;
		return;
	}else{
		echo 2;
		return;
	}
	
}else if($_GET['act'] == 'edit'){
	
	$attr_id = $_GET['attr_id']+0;
	$attr_row = $attr->get_attr_row($attr_id);
	$cat_id  = $attr_row['cat_id'];
	$cat_list = $attr->get_cat_list();
//print_r($attr_row);exit;
	$smarty->assign('attr_id', $attr_id);
	$smarty->assign('attr_row', $attr_row);
	$smarty->assign('cat_id', $cat_id);
	$smarty->assign('cat_list', $cat_list);
	$smarty->assign('judge', 'edit');
	$smarty->assign('title', '添加属性');
	$smarty->assign('url', 'attribute.php?act=list');
	$smarty->assign('link', '商品属性');
	
	$smarty->display('./admin/attribute_info.html');
	
}










